<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>推拉流控制工具 - Web版</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" />
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet" />
    <link href="/static/css/styles.css" rel="stylesheet" />
</head>

<body>
    <a href="/" class="btn btn-outline-light home-btn">
        <i class="bi bi-house-door"></i> 首页
    </a>
    <div class="container-fluid">
        <div class="row header text-center">
            <div class="col-12">
                <h3><i class="bi bi-cast me-2"></i>推拉流测试工具 - Web版</h3>
                <p class="text-white">支持大规模推拉流操作</p>
            </div>
        </div>

        <div class="main-content">
            <div class="row equal-height">
                <!-- 左侧控制面板 -->
                <div class="col-lg-6">
                    <div class="card" id="leftCard">
                        <div class="card-header">
                            <i class="bi bi-sliders me-2"></i>推拉流控制面板
                        </div>
                        <div class="card-body">
                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <div class="card h-100">
                                        <h5 class="sub-panel-title"><i class="bi bi-server me-2"></i>服务器设置</h5>
                                        <div class="card-body">
                                            <div class="upload-group">
                                                <input type="text" class="form-control" id="serverAddress"
                                                    value="media1.softtest.cowarobot.com">
                                            </div>
                                            <p class="small text-muted mb-0">支持手动更改服务器</p>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6 mb-3">
                                    <div class="card h-100 media-settings">
                                        <h5 class="sub-panel-title"><i class="bi bi-file-earmark-play me-2"></i>媒体文件设置
                                        </h5>
                                        <div class="card-body">
                                            <div class="upload-group">
                                                <button class="btn btn-info btn-sm upload-btn" id="uploadBtn">
                                                    <i class="bi bi-upload"></i><span>选择文件</span>
                                                </button>
                                                <div class="file-info-container">
                                                    <span id="fileInfo" class="file-info d-none">
                                                        <i class="bi bi-file-earmark-play me-1"></i>
                                                        <span id="fileName"></span>
                                                    </span>
                                                </div>
                                                <input type="file" id="videoFile" class="d-none" accept="video/*">
                                            </div>
                                            <p class="small text-muted mb-0">支持MP4、AVI、MOV等格式</p>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <!-- 推拉流设置 -->
                            <div class="card stream-settings mt-2">
                                <h5 class="sub-panel-title"><i class="bi bi-sliders me-2"></i>推拉流设置</h5>
                                <div class="card-body">
                                    <div class="setting-group">
                                        <h5 class="sub-sub-panel-title"><i class="bi bi-cast me-2"></i>推流设置</h5>
                                        <div class="stream-count-row">
                                            <label class="form-label mb-0">推流路数:</label>
                                            <input type="number" class="form-control stream-count" id="streamCount"
                                                min="1" value="1">
                                        </div>
                                        <div class="mb-3">
                                            <label class="form-label">推流协议</label>
                                            <div class="protocol-scroll">
                                                {% for protocol in config.push.keys() %}
                                                <div class="form-check form-check-inline">
                                                    <input class="form-check-input" type="radio" name="pushProtocol"
                                                        id="push-{{ protocol }}" value="{{ protocol }}" {% if loop.first
                                                        %}checked{% endif %}>
                                                    <label class="form-check-label" for="push-{{ protocol }}">{{
                                                        protocol
                                                        }}</label>
                                                </div>
                                                {% endfor %}
                                            </div>
                                        </div>

                                        <div id="rtpSettings">
                                            <div class="mb-3">
                                                <label class="form-label">RTP高级设置</label>
                                                <div>
                                                    <div class="form-check form-check-inline">
                                                        <input class="form-check-input" type="radio" name="rtpMode"
                                                            id="rtpLocal" value="local" checked>
                                                        <label class="form-check-label" for="rtpLocal">本地</label>
                                                    </div>
                                                    <div class="form-check form-check-inline">
                                                        <input class="form-check-input" type="radio" name="rtpMode"
                                                            id="rtpWvp" value="wvp">
                                                        <label class="form-check-label" for="rtpWvp">WVP</label>
                                                        <span class="text-muted ms-2 small" id="wvpTip"
                                                            style="display:none">(WVP模式需在WVP平台自行推流，本工具仅支持拉流)
                                                        </span>
                                                    </div>
                                                </div>
                                            </div>

                                            <div id="wvpSettings">
                                                <div class="wvp-settings-row">
                                                    <div class="wvp-input">
                                                        <label class="form-label">设备ID</label>
                                                        <input type="text" class="form-control" id="deviceId">
                                                    </div>
                                                    <div class="wvp-input">
                                                        <label class="form-label">通道ID</label>
                                                        <input type="text" class="form-control" id="channelId">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="status-container">
                                            <div>
                                                <span>推流状态:</span>
                                                <span id="pushStatus" class="ms-2">
                                                    <span class="status-indicator status-inactive"></span>
                                                    <span>未运行</span>
                                                </span>
                                            </div>
                                            <button id="pushBtn" class="btn btn-success">
                                                <i class="bi bi-play-circle me-2"></i>开始推流
                                            </button>
                                        </div>
                                        <div id="pushAnimation" class="progress mt-2">
                                            <div class="progress-bar bg-success progress-bar-animate" role="progressbar"
                                                style="width: 100%"></div>
                                        </div>
                                    </div>

                                    <div class="setting-group">
                                        <h5 class="sub-sub-panel-title"><i class="bi bi-play-btn me-2"></i>拉流设置</h5>
                                        <div class="mb-3">
                                            <label class="form-label">循环模式</label>
                                            <div>
                                                <div class="form-check form-check-inline">
                                                    <input class="form-check-input" type="checkbox" id="loopModeToggle"
                                                        name="loopMode">
                                                    <label class="form-check-label" for="loopModeToggle">启用循环模式</label>
                                                </div>
                                            </div>
                                        </div>
                                        <div id="loopSettings" class="setting-disabled">
                                            <div class="stream-count-row">
                                                <div class="d-flex align-items-center me-3">
                                                    <label class="form-label mb-0 me-2">拉流次数:</label>
                                                    <input type="number" class="form-control stream-count"
                                                        id="pullCount" min="2" value="10">
                                                    <button type="button" class="btn btn-sm btn-link text-info ms-1"
                                                        data-bs-toggle="tooltip" data-bs-custom-class="custom-tooltip"
                                                        title="循环拉流次数">
                                                        <i class="bi bi-question-circle"></i>
                                                    </button>
                                                </div>

                                                <div class="d-flex align-items-center me-3">
                                                    <label class="form-label mb-0 me-2">拉流时长(秒):</label>
                                                    <input type="number" class="form-control stream-count"
                                                        id="pullDuration" min="1" value="5">
                                                    <button type="button" class="btn btn-sm btn-link text-info ms-1"
                                                        data-bs-toggle="tooltip" data-bs-custom-class="custom-tooltip"
                                                        title="每次拉流的持续时间，到时间后自动停止拉流">
                                                        <i class="bi bi-question-circle"></i>
                                                    </button>
                                                </div>

                                                <div class="d-flex align-items-center">
                                                    <label class="form-label mb-0 me-2">间隔时间(秒):</label>
                                                    <input type="number" class="form-control stream-count"
                                                        id="pullInterval" min="1" value="2">
                                                    <button type="button" class="btn btn-sm btn-link  text-info ms-1"
                                                        data-bs-toggle="tooltip" data-bs-custom-class="custom-tooltip"
                                                        title="下一次开始拉流与上一次停止拉流的间隔时间">
                                                        <i class="bi bi-question-circle"></i>
                                                    </button>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="mb-3">
                                            <label class="form-label">拉流模式</label>
                                            <div>
                                                <div class="form-check form-check-inline">
                                                    <input class="form-check-input" type="radio" name="pullMode"
                                                        id="pullSilent" value="silent" checked>
                                                    <label class="form-check-label" for="pullSilent">无播放器</label>
                                                </div>
                                                <div class="form-check form-check-inline">
                                                    <input class="form-check-input" type="radio" name="pullMode"
                                                        id="pullPlayer" value="player">
                                                    <label class="form-check-label" for="pullPlayer">有播放器</label>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="mb-3">
                                            <label class="form-label">拉流协议</label>
                                            <div class="protocol-scroll">
                                                {% if config.pull and config.pull.player %}
                                                {% for protocol in config.pull.player.keys() %}
                                                <div class="form-check form-check-inline">
                                                    <input class="form-check-input" type="radio" name="pullProtocol"
                                                        id="pull-{{ protocol }}" value="{{ protocol }}" {% if loop.first
                                                        %}checked{% endif %}>
                                                    <label class="form-check-label" for="pull-{{ protocol }}">{{
                                                        protocol
                                                        }}</label>
                                                </div>
                                                {% endfor %}
                                                {% endif %}
                                            </div>
                                        </div>

                                        <div class="status-container">
                                            <div>
                                                <span>拉流状态:</span>
                                                <span id="pullStatus" class="ms-2">
                                                    <span class="status-indicator status-inactive"></span>
                                                    <span>未运行</span>
                                                </span>
                                            </div>
                                            <button id="pullBtn" class="btn btn-warning">
                                                <i class="bi bi-play-circle me-2"></i>开始拉流
                                            </button>
                                        </div>
                                        <div id="pullAnimation" class="progress mt-2">
                                            <div class="progress-bar bg-warning progress-bar-animate" role="progressbar"
                                                style="width: 100%"></div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 右侧日志输出区域 -->
                <div class="col-lg-6">
                    <div class="card" id="rightCard">
                        <div class="card-header d-flex justify-content-between align-items-center">
                            <div>
                                <i class="bi bi-journal-text me-2"></i>日志输出
                            </div>
                            <div>
                                <button id="openTerminalBtn" class="btn btn-sm btn-outline-info me-1">
                                    <i class="bi bi-terminal me-1"></i>终端
                                </button>
                                <button id="clearLogBtn" class="btn btn-sm btn-outline-danger me-1">
                                    <i class="bi bi-trash me-1"></i>清空
                                </button>
                                <button id="clearTempBtn" class="btn btn-sm btn-outline-secondary">
                                    <i class="bi bi-trash me-1"></i>清理临时
                                </button>
                            </div>
                        </div>
                        <div class="card-body p-0">
                            <div class="log-container" id="logContainer"></div>
                            <button id="scrollToBottomBtn" class="scroll-to-bottom active" title="自动滚动">
                                <i class="bi bi-arrow-down-circle"></i>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/socket.io-client@4.7.2/dist/socket.io.min.js"></script>
    <script src="/static/js/stream_control.js"></script>
</body>

</html>